package com.ruoyi.web.controller.data;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.alibaba.fastjson.JSONObject;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.entity.SysUser;
import com.ruoyi.system.domain.SysConfig;
import com.ruoyi.system.service.ISysConfigService;
import com.ruoyi.system.service.ISysUserService;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
//
@Api("HD数据接口")
@Controller
@RequestMapping("/hd/api")
public class HDApiController extends BaseController{
	
    @Autowired
    private ISysConfigService configService;
    
    @Autowired
    private ISysUserService userService;
	
	@ApiOperation("获取IP信息")
	@ResponseBody
	@RequestMapping("/getIpInfo")
	public String getIpInfo()
	{
		SysConfig config = new SysConfig();
		config.setConfigKey("_ip");
		List<SysConfig> configList = configService.selectConfigList(config);
		return JSONObject.toJSONString(configList);
	}
	
	@ApiOperation("获取自定义配置信息")
	@ResponseBody
	@RequestMapping("/getConfigInfo")
	public String getConfigInfo()
	{
		SysConfig config = new SysConfig();
		List<SysConfig> configList = configService.selectConfigList(config);
		return JSONObject.toJSONString(configList);
	}
	
	@ApiOperation("验证用户正确性")
	@ResponseBody
	@RequestMapping("/checkUser")
	public String checkUser(String userName, String userPass, String loginName)
	{
		String resultMsg = "";
		
		SysUser sysUser = new SysUser();
		sysUser.setUserName(userName);
		sysUser.setPassword(userPass);
		sysUser.setLoginName(loginName);
		
		List<SysUser> queryUserResult = userService.selectUserList(sysUser);		
		if(queryUserResult == null || queryUserResult.isEmpty()) {
			resultMsg = "fail-未找到用户["+loginName+"]相关信息";
		}else {
			resultMsg = "success-"+userPass;
		}
		
		return resultMsg;
	}
	
}
